package com.share.lottery.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.share.lottery.R;
import com.share.lottery.model.CaiboRmdBean;

/**
 * @author py
 *搜索页面
 */
public class HomeGridAdapter extends BaseAdapter {
	private BitmapUtils bitmapUtils;
	private List<Integer> userList = new ArrayList<Integer>();
	private  Context context;
	public HomeGridAdapter(Context context) {
		this.context = context;
		if (bitmapUtils == null) {
			bitmapUtils = new BitmapUtils(context);
		}
	}
	public int getCount() {

		return userList.size();
	}


	public Integer getItem(int arg0) {

		return userList.get(arg0);
	}


	public long getItemId(int arg0) {

		return arg0;
	}


	public View getView(int position, View convertView, ViewGroup arg2) {
		Integer caiboRmdBean = userList.get(position);
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_grid_search, null);
			viewHolder = new ViewHolder();
			viewHolder.img_bagg = (ImageView) convertView.findViewById(R.id.img_bag);
			viewHolder.tvJl = (TextView) convertView.findViewById(R.id.tv_jl);
			viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title_name);
			viewHolder.tvZans = (TextView) convertView.findViewById(R.id.tv_zs);
			viewHolder.tvPl = (TextView) convertView.findViewById(R.id.tv_pl);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		return convertView;
	}
	class ViewHolder {

		ImageView img_bagg;//grid的背景图片
		TextView tvJl;//距离
		TextView tvTitle;
		TextView tvZans;//红心数
		TextView tvPl;//评论
	}

	/**
	 * 添加数据
	 * 
	 * @param rows
	 */
	public void addDatas(List<Integer> rows) {

		userList.addAll(rows);

		notifyDataSetChanged();
	}

	/**
	 * 清空数据
	 */
	public void clearDatas() {

		userList.clear();
		notifyDataSetChanged();
	}

}
